package com.esoon.controller;

import com.esoon.entity.CsrBlackList;
import com.esoon.service.CsrBlackListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 名单管理(CsrBlackList)表控制层
 *
 * @author makejava
 * @since 2020-09-22 12:03:58
 */
@Api(tags = "红黑名单接口")
@RestController
@RequestMapping("/v1/CsrBlackList")
public class CsrBlackListController {
    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(CsrBlackListController.class);
    }
    /**
     * 服务对象
     */
    @Resource
    private CsrBlackListService csrBlackListService;
/*
 * @return=
 **/

@ApiOperation(value = "根据电话号码查询红黑名单" ,notes =
        "            result = 0 查询成功\n" +
        "            result = 1 查询异常\n" +
        "            result = 2 初始内容，表示查询结束/当查询结果为“”时返回2\n" +
        "            result = 3 当获取到的dtCode为black_phone的时候，返回该值，表示查询到该电话号码为黑名单\n" +
        "            result = 4  当获取到的dtCode为red_phone的时候，返回该值，表示查询到该电话号码为红名单")

    @RequestMapping(value = {"/selectByPhoneNumber"}, method = {RequestMethod.GET})
    public String selectByPhoneNumber(@RequestParam String blPhone,@RequestParam String tenantCode){
    //在程序进入到这里的时候创建一个时间对象，根据该时间点获取之前三十分钟的时间点。
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
    simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");
    Calendar instance = Calendar.getInstance();
    String nowTime = simpleDateFormat.format(instance.getTime());
    logger.info("invoking the 'red black List' interface, interface url = '/v1/CsrBlackList/selectByPhoneNumber' , the requestParam : blPhone = [{}] , tenantCode = [{}] , nowTime = [{}]",blPhone,tenantCode,nowTime);
    return csrBlackListService.selectByPhoneNumber(blPhone,tenantCode,nowTime);
    }

}